{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "08ccfcc9",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "50afc045",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "a6ead1a4",
   "metadata": {},
   "outputs": [],
   "source": [
    "from pandas import Series, DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "51138927",
   "metadata": {},
   "outputs": [],
   "source": [
    "obj = pd.Series([4,7,-5,3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "0c11f28e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    4\n",
       "1    7\n",
       "2   -5\n",
       "3    3\n",
       "dtype: int64"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "obj"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "3666fd93",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<PandasArray>\n",
       "[4, 7, -5, 3]\n",
       "Length: 4, dtype: int64"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "obj.array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "01598691",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RangeIndex(start=0, stop=4, step=1)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "obj.index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "72918c1c",
   "metadata": {},
   "outputs": [],
   "source": [
    "obj2 = pd.Series([1,2,3,4], index=['a', 'b', 'c', 'd'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "3c7b9556",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "a    1\n",
       "b    2\n",
       "c    3\n",
       "d    4\n",
       "dtype: int64"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "obj2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "67e7cca6",
   "metadata": {},
   "outputs": [],
   "source": [
    "obj2[\"a\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "1d836999",
   "metadata": {},
   "outputs": [],
   "source": [
    "obj2[['a', 'b']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "c0415cb0",
   "metadata": {},
   "outputs": [],
   "source": [
    "obj2['e'] = -5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "e161918f",
   "metadata": {},
   "outputs": [],
   "source": [
    "obj2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "2e9a6b13",
   "metadata": {},
   "outputs": [],
   "source": [
    "obj2[obj2>0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "9338e0db",
   "metadata": {},
   "outputs": [],
   "source": [
    "obj2 * 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "e0f155b5",
   "metadata": {},
   "outputs": [],
   "source": [
    "\"c\" in obj2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "c0810103",
   "metadata": {},
   "outputs": [],
   "source": [
    "2 in obj2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "26ef007d",
   "metadata": {},
   "outputs": [],
   "source": [
    "sdata = {\"Ohio\": 35000, \"Texas\": 71000, \"Oregon\": 16000, \"Utah\": 5000}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "76b5a8d3",
   "metadata": {},
   "outputs": [],
   "source": [
    "obj3 = pd.Series(sdata)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "4132ac40",
   "metadata": {},
   "outputs": [],
   "source": [
    "obj3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "5382b393",
   "metadata": {},
   "outputs": [],
   "source": [
    "np.exp(obj2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "5e110330",
   "metadata": {},
   "outputs": [],
   "source": [
    "obj3.to_dict()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "9366088f",
   "metadata": {},
   "outputs": [],
   "source": [
    "states = [\"California\", \"Ohio\", \"Oregon\", \"Texas\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "91066687",
   "metadata": {},
   "outputs": [],
   "source": [
    "obj4 = pd.Series(sdata, index=states)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "4be7c20e",
   "metadata": {},
   "outputs": [],
   "source": [
    "obj4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "51b84a36",
   "metadata": {},
   "outputs": [],
   "source": [
    "pd.isna(obj4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "ddf86268",
   "metadata": {},
   "outputs": [],
   "source": [
    "pd.notna(obj4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "df38ac31",
   "metadata": {},
   "outputs": [],
   "source": [
    "obj3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "063320d1",
   "metadata": {},
   "outputs": [],
   "source": [
    "obj4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "b097885b",
   "metadata": {},
   "outputs": [],
   "source": [
    "obj3 + obj4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "41e7a7a5",
   "metadata": {},
   "outputs": [],
   "source": [
    "obj4.name = \"population\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "ad1b6fb8",
   "metadata": {},
   "outputs": [],
   "source": [
    "obj4.index.name = \"state\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "8eaf6c0c",
   "metadata": {},
   "outputs": [],
   "source": [
    "obj4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "b08bd5b5",
   "metadata": {},
   "outputs": [],
   "source": [
    "obj"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "38e82ffc",
   "metadata": {},
   "outputs": [],
   "source": [
    "obj.index =  [\"Bob\", \"Steve\", \"Taff\", \"Mike\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "95a4b416",
   "metadata": {},
   "outputs": [],
   "source": [
    "obj"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "ce1129f9",
   "metadata": {},
   "outputs": [],
   "source": [
    "data = {\"state\": [\"Ohio\", \"Ohio\", \"Ohio\", \"Nevada\", \"Nevada\", \"Nevada\"],\n",
    "        \"year\": [2000, 2001, 2002, 2001, 2002, 2003],\n",
    "        \"pop\": [1.5, 1.7, 3.6, 2.4, 2.9, 3.2]}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "be8f891a",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame = pd.DataFrame(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "59834f1e",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "c1536cfc",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame.head() # delect only first five rows"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "2d7f561a",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame.tail() # return the last five rows"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "95ac53bb",
   "metadata": {},
   "outputs": [],
   "source": [
    "pd.DataFrame(data, columns=['year', 'state', 'pop']) # spetify the columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "68cde17e",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame2 = pd.DataFrame(data, columns=[\"year\", \"state\", \"pop\", \"debt\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "cb39cae5",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "1ba0af39",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame2.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "569a87f7",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame2['state']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "d29eb0ef",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame2.state"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "e631519a",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame2.loc[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "4a43e61c",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame2.iloc[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "1274ba35",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame2.debt = 16.5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "492a5111",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "ee97ca2e",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame2.debt = np.arange(6.0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "5b36ef32",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "cb47346c",
   "metadata": {},
   "outputs": [],
   "source": [
    "val = pd.Series([-1.2, -1.5, -1.7], index=[\"two\", \"four\", \"five\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "13d5f6bb",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame2.debt = val"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "81fa6885",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "3306ca2a",
   "metadata": {},
   "outputs": [],
   "source": [
    "val = pd.Series([-1.2, -1.4, -1, 7])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "e07e649b",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame2.debt = val"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "a9174f89",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "78b2afd8",
   "metadata": {},
   "outputs": [],
   "source": [
    "val = pd.Series([-1.2, -1.4, -1.7], index=[2,3,4])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "b231dbd5",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame2.debt = val"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "20017410",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "ad0a067f",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame2[\"eastern\"] = (frame2['state'] == 'Ohio')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "03f63cc1",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "id": "00af65bf",
   "metadata": {},
   "outputs": [],
   "source": [
    "del frame2['eastern']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "id": "2b40f34c",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "id": "f5451027",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame2.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "5e9e56d0",
   "metadata": {},
   "outputs": [],
   "source": [
    "In [72]: populations = {\"Ohio\": {2000: 1.5, 2001: 1.7, 2002: 3.6},\n",
    "                        \"Nevada\": {2001: 2.4, 2002: 2.9}}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "id": "65b17896",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame3 = pd.DataFrame(populations)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "id": "d6f935f7",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "88697db9",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame3.T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "34515b58",
   "metadata": {},
   "outputs": [],
   "source": [
    "populations"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "id": "0d85f705",
   "metadata": {},
   "outputs": [],
   "source": [
    "pd.DataFrame(populations, index=[2001, 2002, 2003])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "id": "86632afd",
   "metadata": {},
   "outputs": [],
   "source": [
    "pdata = {'Ohio': frame3['Ohio'][:-1],\n",
    "        'Nevada': frame3['Nevada'][:2]}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "id": "6df4d740",
   "metadata": {},
   "outputs": [],
   "source": [
    "pd.DataFrame(pdata)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "id": "131f23d9",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame3.index.name = 'year'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "id": "f6c25999",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "id": "dd3e9407",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame3.columns.name = 'state'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "id": "e6d2e50c",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "id": "41f9f2e3",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "id": "f63eebeb",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame3.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "id": "428a793c",
   "metadata": {},
   "outputs": [],
   "source": [
    "pd.Index([\"foo\", \"foo\", \"bar\", \"bar\"]) # contain duplicate label"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "id": "aa5b8e48",
   "metadata": {},
   "outputs": [],
   "source": [
    "obj = pd.Series([4.5, 7.2, -5.3, 3.6], index=[\"d\", \"b\", \"a\", \"c\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "id": "877f8350",
   "metadata": {},
   "outputs": [],
   "source": [
    "obj"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "id": "941590df",
   "metadata": {},
   "outputs": [],
   "source": [
    "obj2 = obj.reindex([\"a\", \"b\", \"c\", \"d\", \"e\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "id": "864d2613",
   "metadata": {},
   "outputs": [],
   "source": [
    "obj2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "id": "6008cf07",
   "metadata": {},
   "outputs": [],
   "source": [
    "obj3 = pd.Series([\"blue\", \"purple\", \"yellow\"], index=[0, 2, 4])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "id": "445166ff",
   "metadata": {},
   "outputs": [],
   "source": [
    "obj3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "id": "355ab61f",
   "metadata": {},
   "outputs": [],
   "source": [
    "obj3.reindex(np.arange(6), method='ffill')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "id": "56631f37",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame = pd.DataFrame(np.arange(9).reshape(3,3)\n",
    "                    ,index = ['a', 'c', 'd']\n",
    "                    ,columns = [\"Ohio\", \"Texas\", \"California\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "id": "b05ddd39",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "id": "526ba24b",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame.reindex(index=['a','b','d','e'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "id": "890d70cc",
   "metadata": {},
   "outputs": [],
   "source": [
    "states = [\"Texas\", \"Utah\", \"California\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "id": "f2cd74f0",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame.reindex(columns=states)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "id": "c4fd8773",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame.reindex(states, axis='columns')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "id": "fc97a4c1",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame.loc[[\"a\", \"d\", \"c\"], [\"California\", \"Texas\"]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "id": "3f956aca",
   "metadata": {},
   "outputs": [],
   "source": [
    "obj = pd.Series(np.arange(5), index=['a','b','c','d','e'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "id": "77582ce1",
   "metadata": {},
   "outputs": [],
   "source": [
    "obj"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "id": "e9d9a4bd",
   "metadata": {},
   "outputs": [],
   "source": [
    "new_obj = obj.drop('c')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "id": "5f901535",
   "metadata": {},
   "outputs": [],
   "source": [
    "new_obj"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "id": "c6e5593f",
   "metadata": {},
   "outputs": [],
   "source": [
    "obj.drop(['b', 'd'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "id": "4d23dda6",
   "metadata": {},
   "outputs": [],
   "source": [
    "obj"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "id": "2511b743",
   "metadata": {},
   "outputs": [],
   "source": [
    "data = pd.DataFrame(np.arange(16).reshape((4, 4)),\n",
    "                    index=[\"Ohio\", \"Colorado\", \"Utah\", \"New York\"],\n",
    "                    columns=[\"one\", \"two\", \"three\", \"four\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "id": "b7ee448d",
   "metadata": {},
   "outputs": [],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "id": "b74fcb0b",
   "metadata": {},
   "outputs": [],
   "source": [
    "data.drop(index=['Colorado', 'Ohio'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "id": "2182ebdd",
   "metadata": {},
   "outputs": [],
   "source": [
    "data.drop(columns=['two'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "id": "2fd05cbc",
   "metadata": {},
   "outputs": [],
   "source": [
    "data = pd.DataFrame(np.arange(16).reshape((4, 4)),\n",
    "                    index=[\"Ohio\", \"Colorado\", \"Utah\", \"New York\"],\n",
    "                    columns=[\"one\", \"two\", \"three\", \"four\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "id": "979a42f7",
   "metadata": {},
   "outputs": [],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "id": "7c2ce2e2",
   "metadata": {},
   "outputs": [],
   "source": [
    "data['one']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "id": "ce7e5f5d",
   "metadata": {},
   "outputs": [],
   "source": [
    "data.loc[[\"Colorado\", \"New York\"]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "id": "801ea97e",
   "metadata": {},
   "outputs": [],
   "source": [
    "data.loc[:, ['one', 'two']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "id": "9adb2a81",
   "metadata": {},
   "outputs": [],
   "source": [
    "data.iloc[:1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "id": "76f8a31c",
   "metadata": {},
   "outputs": [],
   "source": [
    "data.iloc[:, :2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "id": "3ab78222",
   "metadata": {},
   "outputs": [],
   "source": [
    "s1 = pd.Series([7.3, -2.5, 3.4, 1.5], index=[\"a\", \"c\", \"d\", \"e\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "id": "8f40a928",
   "metadata": {},
   "outputs": [],
   "source": [
    "s2 = pd.Series([-2.1, 3.6, -1.5, 4, 3.1],\n",
    "                index=[\"a\", \"c\", \"e\", \"f\", \"g\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "id": "912c60b9",
   "metadata": {},
   "outputs": [],
   "source": [
    "s1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "id": "58bc1b39",
   "metadata": {},
   "outputs": [],
   "source": [
    "s2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 118,
   "id": "f9585191",
   "metadata": {},
   "outputs": [],
   "source": [
    "s1 + s2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "id": "b8921bea",
   "metadata": {},
   "outputs": [],
   "source": [
    "df1 = pd.DataFrame(np.arange(9.).reshape((3, 3)), columns=list(\"bcd\"),\n",
    "                   index=[\"Ohio\", \"Texas\", \"Colorado\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 120,
   "id": "64cec772",
   "metadata": {},
   "outputs": [],
   "source": [
    "df2 = pd.DataFrame(np.arange(12.).reshape((4, 3)), columns=list(\"bde\"),\n",
    "                   index=[\"Utah\", \"Ohio\", \"Texas\", \"Oregon\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "id": "dd3b4dd5",
   "metadata": {},
   "outputs": [],
   "source": [
    "df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "id": "914a4866",
   "metadata": {},
   "outputs": [],
   "source": [
    "df2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "id": "e2cd4675",
   "metadata": {},
   "outputs": [],
   "source": [
    "df1+df2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 124,
   "id": "a20a49ad",
   "metadata": {},
   "outputs": [],
   "source": [
    "df1 = pd.DataFrame(np.arange(12.).reshape((3, 4)),\n",
    "                   columns=list(\"abcd\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "id": "1ad835de",
   "metadata": {},
   "outputs": [],
   "source": [
    "df2 = pd.DataFrame(np.arange(20.).reshape((4, 5)),\n",
    "                   columns=list(\"abcde\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 126,
   "id": "db9087b9",
   "metadata": {},
   "outputs": [],
   "source": [
    "df2.loc[1, 'b'] = np.nan"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 127,
   "id": "8d840129",
   "metadata": {},
   "outputs": [],
   "source": [
    "df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 128,
   "id": "5a952d74",
   "metadata": {},
   "outputs": [],
   "source": [
    "df2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 129,
   "id": "3e1f2613",
   "metadata": {},
   "outputs": [],
   "source": [
    "df1 + df2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 130,
   "id": "3cc2b334",
   "metadata": {},
   "outputs": [],
   "source": [
    "df1.add(df2, fill_value=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 131,
   "id": "a8b24416",
   "metadata": {},
   "outputs": [],
   "source": [
    "1/df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 132,
   "id": "547e9eaa",
   "metadata": {},
   "outputs": [],
   "source": [
    "df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 133,
   "id": "c7e11c93",
   "metadata": {},
   "outputs": [],
   "source": [
    "df1.reindex(columns=df2.columns)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 134,
   "id": "a948d594",
   "metadata": {},
   "outputs": [],
   "source": [
    "df1.reindex(columns=df2.columns, fill_value=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 135,
   "id": "ee91ea6e",
   "metadata": {},
   "outputs": [],
   "source": [
    "df1.div(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 136,
   "id": "f1f97e1e",
   "metadata": {},
   "outputs": [],
   "source": [
    "df1.rdiv(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 137,
   "id": "613dcf09",
   "metadata": {},
   "outputs": [],
   "source": [
    "arr = np.arange(12.).reshape(3,4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 138,
   "id": "287a23d8",
   "metadata": {},
   "outputs": [],
   "source": [
    "arr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 139,
   "id": "26bf6d07",
   "metadata": {},
   "outputs": [],
   "source": [
    "arr[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 140,
   "id": "b404aad2",
   "metadata": {},
   "outputs": [],
   "source": [
    "arr - arr[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 141,
   "id": "bfbe3002",
   "metadata": {},
   "outputs": [],
   "source": [
    "arr - arr[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 142,
   "id": "04e4ee11",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame = pd.DataFrame(np.arange(12.).reshape((4, 3)),\n",
    "                     columns=list(\"bde\"),\n",
    "                     index=[\"Utah\", \"Ohio\", \"Texas\", \"Oregon\"])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 143,
   "id": "bded3aa7",
   "metadata": {},
   "outputs": [],
   "source": [
    "series = frame.iloc[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 144,
   "id": "67d692e1",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 145,
   "id": "5c4100cd",
   "metadata": {},
   "outputs": [],
   "source": [
    "series"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 146,
   "id": "a656ac2e",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame - series"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 147,
   "id": "098be897",
   "metadata": {},
   "outputs": [],
   "source": [
    "series2 = pd.Series(np.arange(3), index=[\"b\", \"e\", \"f\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 148,
   "id": "287f36b6",
   "metadata": {},
   "outputs": [],
   "source": [
    "series2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 149,
   "id": "ab046f25",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame - series2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 150,
   "id": "3a4915de",
   "metadata": {},
   "outputs": [],
   "source": [
    "series3 = frame['d']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 151,
   "id": "03694cf0",
   "metadata": {},
   "outputs": [],
   "source": [
    "series3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 153,
   "id": "7785f521",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame = pd.DataFrame(np.random.standard_normal((4,3)))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
